//#ifndef comp_js
//#define comp_js 1

//#include "press.js"
//#include "outstream.js"
//#include "compdict.js"

  // LZW compression algorithm. See http://en.wikipedia.org/wiki/LZW
pressJs.compress = function(str) {
  var output = new OutStream();
  var l = str.length;
  if (!l) return output.bytestream;
  var dict = new CompressDictionary();
  var numBits = dict.ValSizeInBits();
  var w = "";
  for(var i = 0; i < l; ++i) {
    var c = str.charAt(i);
    if(dict.Exists(w + c)) {
      w = w + c;
    } else {
      numBits = dict.Insert(w + c);
      output.Write(dict.Lookup(w), numBits); // Looks-up null on first iteration.
      w = c;
    }
  }
  output.Write(dict.Lookup(w), numBits);
  return output.toString();
}

//#endif

